package com.companyName.sample.service.impl.sys;

import com.companyName.sample.bean.dto.sys.Tree;
import com.companyName.sample.common.util.CommUtil;
import com.companyName.sample.data.entity.ResourcePo;
import com.companyName.sample.data.entity.UserPo;
import com.companyName.sample.service.business.ResourceBiz;
import com.companyName.sample.service.config.ServiceConfig;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.companyName.sample.data.mapper.ResourceMapper;
import com.companyName.sample.data.mapper.RoleMapper;
import com.companyName.sample.data.mapper.UserRoleMapper;
import com.companyName.sample.bean.dto.sys.ResourceDto;
import com.companyName.sample.bean.dto.sys.UserDto;
import com.companyName.sample.api.service.sys.ResourceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
public class ResourceServiceImpl implements ResourceService {

    private static Logger logger = LoggerFactory.getLogger(ResourceServiceImpl.class);

    @Autowired
    private ResourceBiz resourceBiz;

    @Override
    public List<Tree> findTree(UserDto userDto) {
        UserPo userPo = new UserPo();
        CommUtil.copyProperties(userDto, userPo);
        return resourceBiz.findTree(userPo);
    }

    @Override
    public List<ResourceDto> findResourceAll() {
        return resourceBiz.findResourceAll();
    }

    @Override
    public void addResource(ResourceDto resourceDto) {
        ResourcePo resourcePo = new ResourcePo();
        CommUtil.copyProperties(resourceDto, resourcePo);
        resourceBiz.addResource(resourcePo);
    }

    @Override
    public List<Tree> findAllTree() {
        return resourceBiz.findAllTree();
    }

    @Override
    public List<Tree> findAllTrees() {
        return resourceBiz.findAllTrees();
    }


    @Override
    public void updateResource(ResourceDto resourceDto) {
        ResourcePo resourcePo = new ResourcePo();
        CommUtil.copyProperties(resourceDto, resourcePo);
        int update = resourceBiz.updateResource(resourcePo);
        if (update != 1) {
            throw new RuntimeException("更新失败");
        }
    }

    @Override
    public ResourceDto findResourceById(Long id) {
        return resourceBiz.findResourceById(id);
    }

    @Override
    public void deleteResourceById(Long id) {
        int delete = resourceBiz.deleteResourceById(id);
        if (delete != 1) {
            throw new RuntimeException("删除失败");
        }
    }

}
